from django.db import models



# Create your models here.
class UserName(models.Model):
	username = models.CharField(max_length=32, null=False)
	password = models.CharField(max_length=32, null=False)
	phone_number = models.CharField(max_length=18, null=False)
	photo = models.CharField(max_length=32, null=True, blank=True)
	ad = models.OneToOneField('Gender', db_constraint=False)
	roles = models.ManyToManyField('Role')

	def get_role_name(self):
		return ','.join([i.name for i in self.roles.all()])


class Gender(models.Model):
	sex_choice = (
		(0, '女'),
		(1, '男'),
	)

	sex = models.IntegerField(choices=sex_choice, default=1)
	addr = models.CharField(max_length=64)


class Role(models.Model):
	role_name = models.CharField(max_length=32)
	photo = models.CharField(max_length=16,  null=True)
	avatar = models.FileField(upload_to='avatar',null=True)


